package com.ymatou.iapi.liveseller.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.liveseller.parameter.CreateModelBean;
import com.ymatou.iapi.liveseller.service.CreateModelCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.livetv.Model;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
/**
*创建模特
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CreateModel{
	private static CreateModelBean createmodelBean;
	private static CreateModelCall createmodelCall;
	LiveRoomWapper LiveRoomWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建模特");
	}

	@Before
	public void caseUp() {
		createmodelBean=new CreateModelBean();
		createmodelCall=new CreateModelCall();
		LiveRoomWapper=new LiveRoomWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(createmodelCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateModel_001() {
		Logger.start(true,"创建模特成功");
		try {
			int userid=1;
			LiveRoomWapper.deleteModelByUserId(userid);
			createmodelBean.setHeight(1);
			createmodelBean.setWeight(2);
			createmodelBean.setUserId(userid);
			createmodelBean.setNickName("nick");
			createmodelCall.setData(createmodelBean);
			createmodelCall.callService();			
			Logger.verifyEquals("200", createmodelCall.getString("Code"), "验证code");
			int id=Integer.valueOf( createmodelCall.getString("Data"));
			Model modle = LiveRoomWapper.selectModelById(id).get(0);
			Logger.verifyEquals(0, modle.getAction(), "验证action");
			Logger.verifyEquals(createmodelBean.getHeight(), modle.getHeight(), "验证getHeight");
			Logger.verifyEquals(createmodelBean.getWeight(), modle.getWeight(), "验证getWeight");
			Logger.verifyEquals(createmodelBean.getNickName(), modle.getNickName(), "验证getNickName");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_CreateModel_002() {
		Logger.start(true,"不输入userid失败");
		try {
			int userid=1;
			createmodelBean.setHeight(1);
			createmodelBean.setWeight(2);
//			createmodelBean.setUserId(userid);
			createmodelBean.setNickName("nick");
			createmodelCall.setData(createmodelBean);
			createmodelCall.callService();			
			Logger.verifyEquals("400", createmodelCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_CreateModel_003() {
		Logger.start(true,"不输入nickName失败");
		try {
			int userid=1;
			createmodelBean.setHeight(1);
			createmodelBean.setWeight(2);
			createmodelBean.setUserId(userid);
//			createmodelBean.setNickName("nick");
			createmodelCall.setData(createmodelBean);
			createmodelCall.callService();			
			Logger.verifyEquals("400", createmodelCall.getString("Code"), "验证code");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_CreateModel_004() {
		Logger.start(true,"不输入height失败");
		try {
			int userid=1;
//			createmodelBean.setHeight(1);
			createmodelBean.setWeight(2);
			createmodelBean.setUserId(userid);
			createmodelBean.setNickName("nick");
			createmodelCall.setData(createmodelBean);
			createmodelCall.callService();			
			Logger.verifyEquals("400", createmodelCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_CreateModel_005() {
		Logger.start(true,"不输入weight失败");
		try {
			int userid=1;
			createmodelBean.setHeight(1);
//			createmodelBean.setWeight(2);
			createmodelBean.setUserId(userid);
			createmodelBean.setNickName("nick");
			createmodelCall.setData(createmodelBean);
			createmodelCall.callService();			
			Logger.verifyEquals("400", createmodelCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_CreateModel_006() {
		Logger.start(true,"输入nickName超过10个字失败");
		try {
			int userid=1;
			createmodelBean.setHeight(1);
			createmodelBean.setWeight(2);
			createmodelBean.setUserId(userid);
			createmodelBean.setNickName("昵称超过10个字符会失败");
			createmodelCall.setData(createmodelBean);
			createmodelCall.callService();			
			Logger.verifyEquals("400", createmodelCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_CreateModel_007() {
		Logger.start(true,"输入height小于0失败");
		try {
			int userid=1;
			createmodelBean.setHeight(-1);
			createmodelBean.setWeight(2);
			createmodelBean.setUserId(userid);
			createmodelBean.setNickName("nick");
			createmodelCall.setData(createmodelBean);
			createmodelCall.callService();			
			Logger.verifyEquals("400", createmodelCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_CreateModel_008() {
		Logger.start(true,"输入weight小于0失败");
		try {
			int userid=1;
			createmodelBean.setHeight(1);
			createmodelBean.setWeight(-2);
			createmodelBean.setUserId(userid);
			createmodelBean.setNickName("nick");
			createmodelCall.setData(createmodelBean);
			createmodelCall.callService();			
			Logger.verifyEquals("400", createmodelCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CreateModel_009() {
		Logger.start(true,"当前模特5个再次创建失败");
		try {
			int userid=1;
			LiveRoomWapper.deleteModelByUserId(userid);
			for (int i = 0; i < 5; i++) {
				createmodelBean.setHeight(1);
				createmodelBean.setWeight(2);
				createmodelBean.setUserId(userid);
				createmodelBean.setNickName("nick"+i);
				createmodelCall.setData(createmodelBean);
				createmodelCall.callService();			
				Logger.verifyEquals("200", createmodelCall.getString("Code"), "验证code");
			}
			createmodelBean.setHeight(1);
			createmodelBean.setWeight(2);
			createmodelBean.setUserId(userid);
			createmodelBean.setNickName("nickend");
			createmodelCall.setData(createmodelBean);
			createmodelCall.callService();			
			Logger.verifyEquals("201", createmodelCall.getString("Code"), "验证code");
			//最多支持设置5个模特
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CreateModel_010() {
		Logger.start(true,"当前模特5个删除1个后再次创建成功");
		try {
			int userid=1;
			LiveRoomWapper.deleteModelByUserId(userid);
			for (int i = 0; i < 5; i++) {
				createmodelBean.setHeight(1);
				createmodelBean.setWeight(2);
				createmodelBean.setUserId(userid);
				createmodelBean.setNickName("nick"+i);
				createmodelCall.setData(createmodelBean);
				createmodelCall.callService();			
				Logger.verifyEquals("200", createmodelCall.getString("Code"), "验证code");
			}
			int lastid=Integer.valueOf( createmodelCall.getString("Data"));
			createmodelBean.setHeight(1);
			createmodelBean.setWeight(2);
			createmodelBean.setUserId(userid);
			createmodelBean.setNickName("nickend");
			createmodelCall.setData(createmodelBean);
			createmodelCall.callService();			
			Logger.verifyEquals("201", createmodelCall.getString("Code"), "验证code");
			
			LiveRoomCallService.DeleteModelById(lastid, userid);
			
			createmodelCall.callService();			
			Logger.verifyEquals("200", createmodelCall.getString("Code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}